package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.result.Result;
import com.sky.service.UserShoppingCardService;
import com.sky.service.impl.UsershoppingCardServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class UserShoppingCardController {

    @Autowired
    private UsershoppingCardServiceImpl userShoppingCardService;

    @GetMapping("/user/shoppingCart/list")
    public Result list() {
        List list = userShoppingCardService.list();
        return Result.success(list);
    }

    @PostMapping("/user/shoppingCart/add")
    public Result save(@RequestBody ShoppingCartDTO shoppingCartDTO){
        userShoppingCardService.add(shoppingCartDTO);
        return Result.success();
    }

    @PostMapping("/user/shoppingCart/sub")
    public Result deleteOne(@RequestBody ShoppingCartDTO shoppingCartDTO){
        userShoppingCardService.deleteOne(shoppingCartDTO);
        return Result.success();
    }

    @DeleteMapping("/user/shoppingCart/clean")
    public Result clean(){
        userShoppingCardService.clean();
        return Result.success();
    }
}
